package database

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var _db *gorm.DB

func init() {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local&timeout=%s", "root", "xie0316lei", "182.92.202.113", 3306, "renter-dev", "10s")
	var err error
	_db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database: " + err.Error())
	}
	sqlDB, _ := _db.DB()
	sqlDB.SetMaxIdleConns(20)  //最大空闲连接属
	sqlDB.SetMaxOpenConns(100) //最大连接数
}

func GetDB() *gorm.DB {
	return _db
}
